package com.caishi.lkx.course.api;

import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.caishi.lkx.common.AdminBaseApi;
import com.caishi.lkx.course.model.VideoNoteModel;
import com.caishi.lkx.course.service.*;
import com.caishi.lkx.exam.ienum.status.NoteVerifyStatus;
import com.caishi.lkx.exam.service.ICategoryService;
import com.zzw.common.Wrappers;
import com.zzw.common.entity.impl.BaseAbsEntity;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.List;


/**
 * @author lkx
 * &#064;date  2024/5/27
 * &#064;description
 */
@Slf4j
@Tag(name = "视频笔记相关接口")
@RestController
@RequestMapping("/kc/course/video/note")
public class VideoNoteApi extends AdminBaseApi<IVideoNoteService, VideoNoteModel, String> {


    @Resource
    private IVideoNoteService videoNoteService;

    @Resource
    private ICategoryService categoryService;


    @Override
    public IVideoNoteService loadService() {
        return videoNoteService;
    }

    @GetMapping("/page-app")
    public IPage<VideoNoteModel> page1(@ModelAttribute Page<VideoNoteModel> page, @ModelAttribute VideoNoteModel model, @NotNull JSONObject otherParam) {
        model.setVerify(1);
        return super.page(page, model, otherParam);
    };

    @Operation(summary = "发表笔记")
    @PostMapping("/update")
    public VideoNoteModel add(@RequestBody VideoNoteModel entity) {
        if (!entity.getOpen()) {
            entity.setVerify(NoteVerifyStatus.pass.getCode());
        }
        return loadService().insert(entity);
    }

    @PutMapping("batch-verify")
    @Operation(summary = "批量审核")
    public Boolean batchVerify(@RequestParam List<String> ids, @RequestParam Integer status) {
        Integer integer = videoNoteService.batchUpdate(null, Wrappers.<VideoNoteModel>lambdaUpdate().in(VideoNoteModel::getId, ids).set(VideoNoteModel::getVerify,status));
        return integer > 0;
    }
    @PutMapping("batch-delete")
    @Operation(summary = "批量删除")
    public Boolean batchDelete(@RequestParam List<String> ids) {
        Integer integer = videoNoteService.batchUpdate(null, Wrappers.<VideoNoteModel>lambdaUpdate().in(VideoNoteModel::getId, ids)
                .set(BaseAbsEntity::getDeleted, true));
        return integer > 0;
    }


}
